clear
  

% findcoordinates_googleapi is a user written function by Thilo calling the google maps api 2018:

    % needs these inputs additional to location vector:

             key_PL_project='ENTER YOUR KEY HERE';
             base_url = 'https://maps.googleapis.com/maps/api/geocode/json?address=';



%  META DATA 

 
      company_name='Bain';
     company_stub='Bain_';
    % Adress_stub='_Addresses';
    
      
    
    
    

                 % Insheet raw data for country k (html source code)
                 rawdatalocation=strcat('ADJUST PATH/',company_name,'/Raw/',company_name,'.xlsx');
                 [~, ~, Alldata] = xlsread(rawdatalocation);    
    
                
                 Offices=Alldata(2:end,1);
                 Office_address=Alldata(2:end,2);
                   
                 Office_nr=size(Office_address,1);
                 
                 Coordinates=cell(Office_nr,3); 
                
            for r=1:Office_nr
                         %Addresses{r,1}=strcat(Data_i(r,2),' ');
                         %C = strsplit(char(Addresses{r,1}),',');
                         [latitud,longitud] = findcoordinates_googleapi(base_url,key_PL_project,Office_address{r,1});
                         Coordinates(r,1)=cellstr(Office_address(r,1));
                         Coordinates(r,2)=num2cell(latitud);
                         Coordinates(r,3)=num2cell(longitud);



            end
            
            
            
            
             
 
 
  
 
  
cd 'ADJUST PATH//Bain/Final'

filename=strcat('Bain_inPLcountries','.xlsx');


% build dataset

Header={'Office','Latitude','Longitude'};
Dataset=vertcat(Header,Coordinates(1:end,:));

xlwrite(char(filename),Dataset)
 
 
    